home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / PIELOGO.ARJ / PIELOGO.C < prev    next >
C/C++ Source or Header  |  1992-02-02  |  13KB  |  435 lines

  1. /* Pielogo.c     Copyright (c) 1992 Kevin Stokes, Pie in the Sky Software */
  2.  
  3. #include <stdio.h>
  4. #include <malloc.h>
  5. #include <math.h>
  6. #include <string.h>
  7. #include "lprgraf.h"
  8. #include "psgraf.h"
  9. #define MAXLINE 512
  10.  
  11. #define NCOL  20
  12. #define NROW  10
  13. #define SCRXMIN 40
  14. #define SCRXMAX 560
  15. #define SCRXSZ 520
  16. #define SCRYMIN 40
  17. #define SCRYMAX 440
  18. #define SCRYSZ 400
  19. #define SCRBXMAX 639
  20. #define SCRBYMAX 479
  21.  
  22. #define PRNXMIN 20
  23. #define PRNXMAX 700
  24. #define PRNXSZ 680
  25. #define PRNYMIN 20
  26. #define PRNYMAX 700
  27. #define PRNYSZ 680
  28. #define    PRNBXMAX 719
  29. #define    PRNBYMAX 719
  30.  
  31. #define PSXMIN 20
  32. #define PSXMAX 700
  33. #define PSXSZ 680
  34. #define PSYMIN 20
  35. #define PSYMAX 700
  36. #define PSYSZ 680
  37. #define    PSBXMAX 719
  38. #define    PSBYMAX 719
  39.  
  40. #define LOWASCII 0x40
  41. #define LOWCHAR 93
  42.  
  43. int    XMIN,XMAX,YMIN,YMAX,XSZ,YSZ,BXMAX,BYMAX;
  44.  
  45. extern int EGALINE(); 
  46. extern int GRMODE();
  47. extern int TXMODE();
  48.  
  49.  
  50. struct fontchar {
  51.  int lglyph;
  52.  int lnpair;
  53.  char *textptr;
  54.  };
  55.  
  56. struct fontchar thefont[1024];
  57.  
  58. int odevice,lastspace,thisspace,prospace;
  59.  
  60. void drawstring();
  61. void drawstringrad();
  62. void drawchar();
  63. void bermsg();
  64.  
  65. halfcircle(centerx,centery,radius,n,thickness)
  66. int centerx,centery,radius,n,thickness;
  67. {
  68.     int    i,iargx1,iargy1,iargx2,iargy2,ii;
  69.     float    theta,fradius,thckdelrad,phasenoise;
  70.         for(ii=0;ii< thickness*3;ii++)
  71.         {
  72.         thckdelrad=(float) thickness*(float) ii/24.-(float)thickness/8.;
  73.     fradius=radius+thckdelrad;
  74.     phasenoise=(float) rand()*3.14159/75./32767.;
  75.     iargx1=centerx+(int) fradius;
  76.     iargy1=centery;
  77.     for(i=0;i<n;i++)
  78.             {
  79.           theta=( (float) (i+1)*3.14159/(float) n)+phasenoise;
  80.           if(theta > 3.14159) theta=3.14159;
  81.           iargx2=centerx+(int) (fradius*cos(theta));
  82.           iargy2=centery-(int) (fradius*sin(theta));
  83.           if(odevice == 0)
  84.          { EGALINE(iargx1,iargy1,iargx2,iargy2,15);
  85.            EGALINE(iargx1+1,iargy1,iargx2+1,iargy2,15); }
  86.             if(odevice == 1) lprdrawline(iargx1,iargy1,iargx2,iargy2,15);
  87.             if(odevice == 2) psline(iargx1,iargy1,iargx2,iargy2);
  88.           iargx1=iargx2;
  89.           iargy1=iargy2;
  90.             }    
  91.        }
  92. }
  93.  
  94.  
  95. circle(centerx,centery,radius,n,thickness)
  96. int centerx,centery,radius,n,thickness;
  97. {
  98.     int    i,iargx1,iargy1,iargx2,iargy2,ii;
  99.     float    theta,fradius,thckdelrad,phasenoise;
  100.         for(ii=0;ii< thickness*3;ii++)
  101.         {
  102.         thckdelrad=(float) thickness*(float) ii/24.-(float)thickness/8.;
  103.     fradius=radius+thckdelrad;
  104.     phasenoise=(float) rand()*3.14159/7./32767.;
  105.     iargx1=centerx+(int) fradius;
  106.     iargy1=centery;
  107.     for(i=0;i<n;i++)
  108.             {
  109.           theta=( (float) (i+1)*2.*3.14159/(float) n)+phasenoise;
  110.           iargx2=centerx+(int) (fradius*cos(theta));
  111.           iargy2=centery-(int) (fradius*sin(theta));
  112.           if(odevice == 0)
  113.          { EGALINE(iargx1,iargy1,iargx2,iargy2,15);
  114.            EGALINE(iargx1+1,iargy1,iargx2+1,iargy2,15); }
  115.             if(odevice == 1) lprdrawline(iargx1,iargy1,iargx2,iargy2);
  116.             if(odevice == 2) psline(iargx1,iargy1,iargx2,iargy2);
  117.           iargx1=iargx2;
  118.           iargy1=iargy2;
  119.             }    
  120.        }
  121. }
  122.  
  123. horizline(iargx1,iargx2,iargy1,thickness)
  124.     int    iargx1,iargy1,iargx2,thickness;
  125. {
  126.     int    i,ii,iargy2,ithick;
  127.     ithick=thickness|1;
  128.     iargy2=iargy1;
  129.         for(ii=0;ii< ithick;ii++)
  130.         {
  131.     if(odevice==0)
  132.           EGALINE(iargx1,iargy1+ii-ithick/2,iargx2,iargy2+ii-ithick/2,15);
  133.     if(odevice==1)
  134.           lprdrawline(iargx1,iargy1+ii-ithick/2,iargx2,iargy2+ii-ithick/2);
  135.     if(odevice==2)
  136.           psline(iargx1,iargy1+ii-ithick/2,iargx2,iargy2+ii-ithick/2);
  137.         }
  138.     
  139. }
  140.  
  141. main(int argc, char *argv[])
  142.  
  143. {
  144.     int i,ii,nch,npair,glyph,linen,irow,icol;
  145.     FILE *inputf;
  146.     char aline[MAXLINE];
  147.     char glyphs[10];
  148.     char npairs[10];
  149. /*        char *lineptr[1024];
  150.     int  linenpair[1024],lineglyph[1024]; */
  151.     int nchars;
  152.     char psname[80];
  153.     
  154. /* printf("Command line: "); */
  155. /* for (i=1;i < argc; i++) printf("%s ",argv[i]); */
  156.  
  157. inputf = fopen("shersh.oc3","r");
  158. if (inputf == NULL) {
  159.   printf("Could not open hersh.oc3 for reading\n");
  160.   exit(0); }
  161. odevice=-1;        /* default is screen output */
  162. if (strcmpi(argv[1],"printer") == 0) odevice=1;
  163. if (strcmpi(argv[1],"screen") == 0) odevice=0;
  164. if (strcmpi(argv[1],"postscript") == 0) odevice=2;
  165. if(odevice==-1) {
  166.   printf("\nUsage :");
  167.   printf("\n");
  168.   printf("\npielogo screen                   Outputs logo to VGA screen");
  169.   printf("\npielogo printer                  Outputs logo to Panasonic 1123/4 printer");
  170.   printf("\npielogo postscript output.ps     Outputs to postscript file output.ps");
  171.   printf("\n");
  172.   exit(0);
  173.   }
  174. if (odevice == 0)
  175. {  XMAX=SCRXMAX;
  176.   YMAX=SCRYMAX;
  177.   XMIN=SCRXMIN;
  178.   YMIN=SCRYMIN;
  179.   XSZ=SCRXSZ;
  180.   YSZ=SCRYSZ;
  181.   BXMAX=SCRBXMAX;
  182.   BYMAX=SCRBYMAX; }
  183. if (odevice == 1)
  184. {  XMAX=PRNXMAX;
  185.   YMAX=PRNYMAX;
  186.   XMIN=PRNXMIN;
  187.   YMIN=PRNYMIN;
  188.   XSZ=PRNXSZ;
  189.   YSZ=PRNYSZ;
  190.   BXMAX=PRNBXMAX;
  191.   BYMAX=PRNBYMAX; }
  192. if (odevice == 2)
  193. {  XMAX=PSXMAX;
  194.   YMAX=PSYMAX;
  195.   XMIN=PSXMIN;
  196.   YMIN=PSYMIN;
  197.   XSZ=PSXSZ;
  198.   YSZ=PSYSZ;
  199.   BXMAX=PSBXMAX;
  200.   BYMAX=PSBYMAX; 
  201. strcpy(psname,argv[2]);        /* put ps output filename in string */
  202. }
  203.  
  204. linen=0;
  205. nchars=0;
  206. prospace=0;
  207. while(fgets(aline,MAXLINE,inputf) != NULL) {
  208.   linen++;
  209.   if( strlen(aline) > 0) {
  210.    if( aline[0] == ' ' )  {
  211.     strncpy(glyphs,aline,5);
  212.     glyphs[5]='\0';
  213.     glyph=strtol(glyphs,NULL,10);
  214.     strncpy(npairs,&aline[5],3);
  215.     npairs[3]='\0';
  216.     npair=strtol(npairs,NULL,10);
  217.     nch=2*npair+8;
  218.     aline[strlen(aline)-1] = '\0' ;
  219.     while(nch != strlen(aline)) {
  220.       fgets(&aline[strlen(aline)],MAXLINE-strlen(aline),inputf);
  221.       linen++;
  222.       aline[strlen(aline)-1] = '\0' ;
  223.       if(strlen(aline) >= MAXLINE-2) { printf("\n Error in font file : %s \n",
  224.         "shersh.oc3");
  225.         printf("%d chars expected, %d chars found in line %d \n",nch,
  226.         strlen(aline),linen);
  227.         exit(0); }
  228.     }
  229.     thefont[nchars].textptr=calloc(nch+2,1);
  230.     if(thefont[nchars].textptr == NULL) { printf("out of mem \n"); exit(0); }
  231.     strcpy(thefont[nchars].textptr,&aline[8]);
  232.     thefont[nchars].lnpair=npair;
  233.     thefont[nchars].lglyph=glyph;
  234.     nchars++;
  235.       }
  236.     }
  237.   }
  238. /* */
  239. if(odevice==0) {
  240.     GRMODE(); }
  241. if(odevice==1) {
  242.    lprinit(); }
  243. if(odevice==2) {
  244.    psinit(psname); }
  245.         horizline(XMIN+1,XMAX-1,YSZ/2+YSZ/4+YMIN,4);
  246.     drawchar(&thefont[93],XSZ/9+XMIN,YSZ/2+YSZ/4+YMIN-23,2.0,2.0,0.);
  247.     drawchar(&thefont[93],XSZ/6+XMIN,YSZ/2+YSZ/4+YMIN-23,2.0,2.0,0.);
  248. /*
  249.        halfcircle(XSZ/2+XMIN,YSZ/2+YMIN,XSZ/6,40,10);
  250.     drawstring("The quick brown fox",XSZ/2+XMIN,YSZ/2+YSZ/6+YMIN,.8,.8,18); 
  251. */
  252.     drawstringrad(
  253. "Pie in the Sky Software",XSZ/2+XSZ/4+XMIN,YSZ/2-YSZ/4+YMIN,
  254. .97,.97,9,64.,2.9); 
  255. if(odevice == 0) {
  256.     getch();
  257.             TXMODE();
  258. }
  259.  
  260. if(odevice == 1) 
  261. {
  262.     lprprint();
  263.     lpremit(12);
  264. }
  265. if(odevice == 2) 
  266. {
  267.     psclose();
  268. }
  269. }
  270.  
  271. void drawstring(stringptr,ixc,iyc,fsfx,fsfy,lsize)
  272. char *stringptr;
  273. int ixc,iyc,lsize;
  274. float fsfx,fsfy;
  275. {
  276. char *mystrptr;
  277. int    ixoff,charindex,i;
  278.     mystrptr=stringptr;
  279.     prospace=1;
  280.     lastspace=0;
  281.     ixoff=0;
  282. /*    while(*mystrptr != "\0")  */
  283.     for(i=0;i<strlen(stringptr);i++)
  284.            {
  285.  
  286.               if(*mystrptr <= 0x5a) 
  287.                   { charindex=(int) *mystrptr - LOWASCII +LOWCHAR ;
  288.                     if(charindex < LOWCHAR) charindex=-1; }
  289.               if(*mystrptr >= 0x61) 
  290.                   { charindex=(int) *mystrptr - (int) 0x61+120+26;
  291.                     if(charindex > 26+120+26 ) charindex=-1; }
  292.           if(*mystrptr == 0x20)
  293.                 { ixoff=ixoff+lsize;  lastspace=0; thisspace=0;}
  294.               mystrptr++;
  295. /*          printf("(%d %d)",(int) *mystrptr - LOWASCII ,charindex); */
  296.               if(charindex > 0) {
  297.                 drawchar(&thefont[charindex],ixc+ixoff,iyc,fsfx,fsfy,0.);
  298.             ixoff=ixoff+(int) ( (float) (lastspace+thisspace)/fsfx);
  299.                 ixoff=ixoff+lsize/5;
  300.               }
  301.  
  302.            }
  303. prospace=0;
  304. lastspace=0;
  305. }          
  306.  
  307. void drawstringrad(stringptr,ixc,iyc,fsfx,fsfy,lsize,lradius,thetastrt)
  308. char *stringptr;
  309. int ixc,iyc,lsize;
  310. float fsfx,fsfy,lradius,thetastrt;
  311. {
  312. char *mystrptr;
  313. int    ixoff,charindex,i,ixchar,iychar;
  314. float    theta,thetaprime;
  315.     mystrptr=stringptr;
  316.     prospace=0;
  317.     lastspace=0;
  318.     theta=thetastrt;
  319.     ixoff=0;
  320. /*    while(*mystrptr != "\0")  */
  321.     for(i=0;i<strlen(stringptr);i++)
  322.            {
  323.  
  324.               if(*mystrptr <= 0x5a) 
  325.                   { charindex=(int) *mystrptr - LOWASCII +LOWCHAR ;
  326.                     if(charindex < LOWCHAR) charindex=-1; }
  327.               if(*mystrptr >= 0x61) 
  328.                   { charindex=(int) *mystrptr - (int) 0x61+120+26;
  329.                     if(charindex > 26+120+26 ) charindex=-1; }
  330.               ixoff=0;
  331.           if(*mystrptr == 0x20)
  332.                 { ixoff=lsize; lastspace=0; thisspace=0;
  333.                 ixoff=ixoff+lsize/4;
  334.                 theta=theta+(float) ixoff/lradius; }
  335.  
  336.               mystrptr++;
  337.               if(charindex > 0) {
  338.         thisspace='R'-(thefont[charindex].textptr)[0]; 
  339.                 theta=theta+(float) thisspace*fsfx/lradius;
  340.         ixchar=ixc+(int) lradius*cos(theta);
  341.         iychar=iyc+(int) lradius*sin(theta);
  342.             thetaprime=theta+3.14159/2.;
  343. /*          printf("(%c %d)",*mystrptr,charindex); */
  344.                 drawchar(&thefont[charindex],
  345. /*                  ixchar,iychar,fsfx,fsfy,theta+3.14159/2.);  */
  346.                   ixchar,iychar,fsfx,fsfy,thetaprime);
  347.             ixoff=ixoff+(int) ( (float) (lastspace+thisspace)*fsfx);
  348.                 ixoff=ixoff+lsize/5;
  349. /*       printf("%i %i %i %c|",lastspace,thisspace,ixoff,*(mystrptr-1)); */
  350.                 theta=theta+(float) ixoff/lradius;
  351.               }
  352.  
  353.            }
  354. prospace=0;
  355. lastspace=0;
  356. }          
  357.  
  358.  
  359. void drawchar(myfontptr,ixc,iyc,fsfx,fsfy,theta)
  360.  
  361. struct fontchar *myfontptr;
  362. int ixc,iyc;
  363. float fsfx,fsfy,theta;
  364.  
  365. {
  366.         int i,ii;
  367.     int argx1,argy1,argx2,argy2,n;
  368.     int iargx1,iargy1,iargx2,iargy2;
  369.     if(prospace != 0) { thisspace=('R'-myfontptr->textptr)[0]; }
  370.              else {thisspace=0; lastspace=0;}
  371.     if((*myfontptr).lnpair > 2)
  372.           {
  373.           argx2=(myfontptr->textptr)[2]-'R'+thisspace;
  374.           argy2=(myfontptr->textptr)[3]-'R';
  375. /*      printf("\n%d %d M",argx1,argy1);        */
  376.           for(ii=0;ii < myfontptr->lnpair-2;ii++)
  377.              {
  378.              if((myfontptr->textptr)[2*ii+4] == ' ')
  379.                 {
  380.                 argx2=(myfontptr->textptr)[2*ii+6]-'R'+thisspace;
  381.                 argy2=(myfontptr->textptr)[2*ii+7]-'R';
  382.                 ii++;
  383. /*        printf("\n"); */
  384.               }
  385.              else
  386.                 {
  387.                 argx1=argx2;
  388.                 argy1=argy2;
  389.                 argx2=(myfontptr->textptr)[2*ii+4]-'R'+thisspace;
  390.                 argy2=(myfontptr->textptr)[2*ii+5]-'R';
  391. /*      printf("\n%d %d %d %d D",argx1,argy1,argx2,argy2); */
  392. /*        iargx1=fsfx*640./1000.*argx1+ixc*640/1000;
  393.         iargx2=fsfx*640./1000.*argx2+ixc*640/1000;
  394.         iargy1=fsfy*480./1000.*argy1+iyc*480/1000;
  395.         iargy2=fsfy*480./1000.*argy2+iyc*480/1000; */
  396.         iargx1=fsfx*argx1*cos(theta)-fsfy*argy1*sin(theta)+ixc;
  397.         if(errno == ERANGE) { printf("Range error"); exit(0); }
  398.         iargx2=fsfx*argx2*cos(theta)-fsfy*argy2*sin(theta)+ixc;
  399.         if(errno == ERANGE) { printf("Range error"); exit(0); }
  400.         iargy1=fsfy*argy1*cos(theta)+fsfx*argx1*sin(theta)+iyc;
  401.         if(errno == ERANGE) { printf("Range error"); exit(0); }
  402.         iargy2=fsfy*argy2*cos(theta)+fsfx*argx2*sin(theta)+iyc;
  403.         if(errno == ERANGE) { printf("Range error"); exit(0); }
  404.         if(iargx1>BXMAX) bermsg(iargx1,iargy1,iargx2,iargy2);
  405.         if(iargx2>BXMAX) bermsg(iargx1,iargy1,iargx2,iargy2);
  406.         if(iargx1<0) bermsg(iargx1,iargy1,iargx2,iargy2);
  407.         if(iargx2<0) bermsg(iargx1,iargy1,iargx2,iargy2);
  408.         if(iargy1>BYMAX) bermsg(iargx1,iargy1,iargx2,iargy2);
  409.         if(iargy2>BYMAX) bermsg(iargx1,iargy1,iargx2,iargy2);
  410.         if(iargy1<0) bermsg(iargx1,iargy1,iargx2,iargy2);
  411.         if(iargy2<0) bermsg(iargx1,iargy1,iargx2,iargy2);
  412.         if(odevice ==0)
  413.          { EGALINE(iargx1,iargy1,iargx2,iargy2,15);
  414.            EGALINE(iargx1+1,iargy1,iargx2+1,iargy2,15); } 
  415.             if(odevice == 1) lprdrawline(iargx1,iargy1,iargx2,iargy2);
  416.             if(odevice == 2) psline(iargx1,iargy1,iargx2,iargy2);
  417. /*        lprdrawline(iargx1+1,iargy1,iargx2+1,iargy2,15); */
  418.                 
  419.                 }
  420.       
  421.              
  422.          }
  423.           }
  424.     if(prospace != 0) { lastspace=(myfontptr->textptr)[1]-'R'; }
  425.     thisspace='R'-(myfontptr->textptr)[0]; 
  426. }
  427.  
  428. void bermsg(iargx1,iargy1,iargx2,iargy2)
  429. int iargx1,iargx2,iargy1,iargy2;
  430. {
  431. printf("%d %d %d %d Boundary Error",iargx1,iargy1,iargx2,iargy2);
  432. exit(0);
  433. }
  434.  
  435.